<template>
  <div class="app-container">
    <el-input
      v-model="filterText"
      placeholder="输入关键词搜索"
      style="margin-bottom: 30px"
    />

    <el-tree
      ref="tree2"
      :data="data2"
      :props="defaultProps"
      :filter-node-method="filterNode"
      class="filter-tree"
      default-expand-all
    />
     <!-- <el-table
      ref="tree2"
      :data="data2"
      style="width: 100%;margin-bottom: 20px;"
      :filter-node-method="filterNode"
      row-key="id"
      border
      default-expand-all>
      <el-table-column prop="title" label="课程分类" sortable width="180"></el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope" >
          <el-button type="text" v-if="scope.row.children " size="mini" >添加课程分类</el-button>
          <el-button type="text" size="mini" @click="() => updateSubject(scope.row)">修改</el-button>
          <el-button type="text" size="mini">删除</el-button>
        </template>
      </el-table-column>
    </el-table> -->
  </div>
</template>

<script>
import subjectApi from "@/api/edu/subject";
export default {
  data() {
    return {
      filterText: "",
      data2: [], //返回所有分类的数据
      defaultProps: {
        children: "children",
        label: "title",
      },
    };
  },
  watch: {
    filterText(val) {
      this.$refs.tree2.filter(val);
    },
  },
  created() {
    this.getAllSubjectList();
  },
  methods: {
    //得到所有分类
    getAllSubjectList() {
      subjectApi.getSubjectList().then((response) => {
        this.data2 = response.data.list;
      });
    },
    //搜索功能
    filterNode(value, data) {
      if (!value) return true;
      return data.title.toLowerCase().indexOf(value) !== -1;
    },
    updateSubject() {
      
    }
  },
};
</script>

